home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 60750 / 60750.xpi / chrome / chromeFiles / content / bindings / bttoolbarbutton.xml < prev   
Extensible Markup Language  |  2010-01-20  |  10KB  |  299 lines

  1. <?xml version="1.0"?>
  2.  
  3. <bindings id="btbuttonBindings"
  4.             xmlns="http://www.mozilla.org/xbl"
  5.             xmlns:html="http://www.w3.org/1999/xhtml"
  6.             xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  7.             xmlns:xbl="http://www.mozilla.org/xbl">
  8.  
  9.     <binding id="bttoolbarbutton" extends="xul:box">
  10.         <content>
  11.         <xul:hbox>
  12.                 <xul:button anonid="bttoolbarbutton-button" xbl:inherits="label,type">
  13.                     <xul:menupopup anonid="bttoolbarbutton-popup">
  14.                         <children/>
  15.                     </xul:menupopup>
  16.                 </xul:button>
  17.             </xul:hbox>
  18.         </content>
  19.         <handlers>
  20.             <handler event="mouseover">
  21.                 <![CDATA[
  22.             if (this.adfeed) {
  23.                 this.buttonTimer = window.setTimeout(this.displayShoppingTip(this), 500);
  24.             }
  25.                 ]]>
  26.             </handler>
  27.             <handler event="mouseout">
  28.                 <![CDATA[
  29.                 if (this.adfeed && this.buttonTimer) {
  30.                     window.clearTimeout(this.buttonTimer);
  31.                     this.buttonTimer = 0;
  32.                 }
  33.                 ]]>
  34.             </handler>
  35.             <handler event="command">
  36.                 <![CDATA[
  37.                     var target;
  38.                     if (event.originalTarget.id) {
  39.                         target = event.originalTarget;
  40.                     } else {
  41.                         target = event.target;
  42.                     }
  43.                     var subject = {};
  44.                     subject.wrappedJSObject = this.brandObject;
  45.                     if (target.hasAttribute("id")) {
  46.                       this.observerService.notifyObservers(subject, "brandthunder", target.id);
  47.                     }
  48.                     if (target.hasAttribute("bt-url")) {
  49.                         this.brandObject.utilities.openLink(this.brandObject, event, target.getAttribute("bt-url"));
  50.                     } else if (target.hasAttribute("bt-sidebar")) {
  51.                       var sidebar = target.getAttribute("bt-sidebar");
  52.                         toggleSidebar(sidebar);
  53.                         if (!document.getElementById(sidebar).hasAttribute("checked")) {
  54.                           document.getElementById("main-window").removeAttribute("btSidebar");
  55.                         }
  56.                     }
  57.                     if (this.hasAttribute("type") && (this.getAttribute("type") == "menu-button")) {
  58.                         if (target.nodeName == "menuitem") {
  59.                           var label;
  60.                           if (target.hasAttribute("value")) {
  61.                             label = target.getAttribute("value");
  62.                           } else {
  63.                             label = target.getAttribute("label");
  64.                           }
  65.                           this.setAttribute("label", label);
  66.                           this.setAttribute("bt-url", target.getAttribute("bt-url"));
  67.                           if (this.btPrefBranch) {
  68.                               this.btPrefBranch.setCharPref(this.id + ".url", target.getAttribute("bt-url"));
  69.                               this.btPrefBranch.setCharPref(this.id + ".label", label);
  70.                           }
  71.                         }
  72.                     }
  73.                     if (this.adfeed) {
  74.                         this.shoppingtooltip.hidePopup();
  75.                     }
  76.                 ]]>
  77.             </handler>
  78.         </handlers>
  79.         <implementation>
  80.             <constructor>
  81.                 <![CDATA[
  82.                 this.observerService = Components.classes["@mozilla.org/observer-service;1"]
  83.                                                                                  .getService(Components.interfaces.nsIObserverService)
  84.  
  85.                 if (this.hasAttribute('btBoomBundle')) {
  86.                     this.btBoomBundle = document.getElementById(this.getAttribute('btBoomBundle'));
  87.                 }
  88.                 if (this.hasAttribute('brand')) {
  89.                     this.brandObject = BrandThunder.clients[this.getAttribute('brand')];
  90.                 }
  91.                 if (this.hasAttribute('adfeed')) {
  92.                     this.adfeed = this.getAttribute('adfeed');
  93.                 }
  94.                 
  95.                 if (this.brandObject) {
  96.                     this.btPrefBranch = Components.classes["@mozilla.org/preferences-service;1"]
  97.                                                                                 .getService(Components.interfaces.nsIPrefService)
  98.                                                                                 .getBranch("extensions.brandthunder.");
  99.                 }
  100.                 if (this.btBoomBundle) {
  101.                     var label = this.getString(this.id + ".label");
  102.                     if (label) {
  103.                         this.setAttribute("label", label);
  104.                     }
  105.                     var type = this.getAttribute("type");
  106.                     switch (type) {
  107.                         case "menu-button":
  108.                             try {
  109.                                 url = this.btPrefBranch.getCharPref(this.id + ".url");
  110.                                 this.setAttribute("bt-url", url);
  111.                             } catch (ex) {}
  112.                             try {
  113.                                 label = this.btPrefBranch.getCharPref(this.id + ".label");
  114.                                 this.setAttribute("label", label);
  115.                             } catch (ex) {}
  116.                         case "menu":
  117.                             var menupopup = getAnonymousElementByAttribute(this, "anonid", "bttoolbarbutton-popup");
  118.                             if (menupopup.childNodes.length == 0) {
  119.                                 var i = 1;
  120.                                 var menuitem;
  121.                                 while ((label = this.getString(this.id + "-" + i + ".label"))) {
  122.                                     if (label.match(/-+/g)) {
  123.                                       menuitem = document.createElement("menuseparator");
  124.                                     } else {
  125.                                       menuitem = document.createElement("menuitem");
  126.                                       menuitem.setAttribute("label", label);
  127.                                       menuitem.setAttribute("id", this.id + "-" + i);
  128.                                       url = this.getString(this.id + "-" + i + ".url");
  129.                                       if (url) {
  130.                                           menuitem.setAttribute("bt-url", url);
  131.                                       }
  132.                                       sidebar = this.getString(this.id + "-" + i + ".sidebar");
  133.                                       if (sidebar) {
  134.                                           menuitem.setAttribute("bt-sidebar", sidebar);
  135.                                       }
  136.                                     }
  137.                                     menupopup.appendChild(menuitem);
  138.                                     i++;
  139.                                 }
  140.                             }
  141.                         default:
  142.                             var url = this.getString(this.id + ".url");
  143.                             if (url) {
  144.                                 this.setAttribute("bt-url", url);
  145.                             } else {
  146.                                 var sidebar = this.getString(this.id + ".sidebar");
  147.                                 if (sidebar) {
  148.                                     this.setAttribute("bt-sidebar", sidebar);
  149.                                 }
  150.                             }
  151.                     }
  152.                     if (this.adfeed) {
  153.                                         var mainPopupSet = document.getElementById("mainPopupSet");
  154.                 this.shoppingtooltip = document.createElement("panel");
  155.                 this.shoppingtooltip.setAttribute("id", this.id + "-tooltip")
  156.                 this.shoppingimage = document.createElement("image");
  157.                 this.shoppingimage.setAttribute("id", this.id + "-tooltip-image");
  158.                 this.shoppingimage.addEventListener("click", this.clickedTip(this), false);
  159.                 this.shoppingimage.addEventListener("mouseover", this.cancelTimeout(this), false);
  160.                 this.shoppingimage.addEventListener("mouseout", this.startTimeout(this), false);
  161.                 this.shoppingtooltip.appendChild(this.shoppingimage);
  162.                 mainPopupSet.appendChild(this.shoppingtooltip);
  163.                 this.getShoppingAdFeed();
  164.  
  165.                     }
  166.                 }
  167.                 ]]>
  168.             </constructor>
  169.             <destructor>
  170.             if (this.adfeed) {
  171.                 this.shoppingimage.removeEventListener("click", this.clickedTip(this), false);
  172.                 this.shoppingimage.removeEventListener("mouseover", this.cancelTimeout(this), false);
  173.                 this.shoppingimage.removeEventListener("mouseout", this.startTimeout(this), false);
  174.             }
  175.             </destructor>
  176.             <field name="btPrefBranch"/>
  177.             <field name="brandObject"/>
  178.             <field name="btBoomBundle"/>
  179.             <field name="observerService"/>
  180.             <field name="adfeed"/>
  181.             <field name="shoppingtooltip"/>
  182.             <field name="shoppingimage"/>
  183.             <field name="popupTimer">
  184.                 0
  185.             </field>
  186.             <field name="buttonTimer">
  187.                 0
  188.             </field>
  189.             <method name="cancelTimeout">
  190.                 <parameter name="btshoppingbutton"/>
  191.                 <body>
  192.                 return function() {
  193.                     if (btshoppingbutton.popupTimer > 0) {
  194.                         window.clearTimeout(btshoppingbutton.popupTimer);
  195.                     }
  196.                 }
  197.                 </body>
  198.             </method>
  199.             <method name="startTimeout">
  200.                 <parameter name="btshoppingbutton"/>
  201.                 <body>
  202.                 return function() {
  203.                     btshoppingbutton.cancelTimeout();
  204.                     function hideShoppingTip() {
  205.                         btshoppingbutton.shoppingtooltip.hidePopup();
  206.                     }
  207.                     btshoppingbutton.popupTimer = window.setTimeout(hideShoppingTip, 2000);
  208.                 }
  209.                 </body>
  210.             </method>
  211.             <method name="displayShoppingTip">
  212.                 <parameter name="btshoppingbutton"/>
  213.                 <body>
  214.                     <![CDATA[
  215.                 return function() {
  216.             if (btshoppingbutton.shoppingimage.hasAttribute("url") &&
  217.                 btshoppingbutton.shoppingimage.hasAttribute("src")) {
  218.                         btshoppingbutton.shoppingtooltip.openPopup(btshoppingbutton, "after_pointer", 0, 0, false, null);
  219.                         if (btshoppingbutton.popupTimer > 0) {
  220.                             window.clearTimeout(btshoppingbutton.popupTimer);
  221.                         }
  222.                         function hideShoppingTip() {
  223.                             btshoppingbutton.shoppingtooltip.hidePopup();
  224.                         }
  225.                         btshoppingbutton.popupTimer = window.setTimeout(hideShoppingTip, 2000);
  226.             }
  227.                 }
  228.                     ]]>
  229.                 </body>
  230.             </method>
  231.             <method name="clickedTip">
  232.                 <parameter name="btshoppingbutton"/>
  233.                 <body>
  234.                 return function(event) {
  235.                     if (event.target.hasAttribute("url")) {
  236.                         btshoppingbutton.brandObject.utilities.openLink(btshoppingbutton.brandObject, event, event.target.getAttribute("url"));
  237.                     }
  238.                     btshoppingbutton.shoppingtooltip.hidePopup();
  239.                 }
  240.                 </body>
  241.             </method>
  242.             <method name="getShoppingAdFeed">
  243.                 <body>
  244.                     <![CDATA[
  245.                     var btshoppingbutton = this;
  246.                     var request = new XMLHttpRequest();
  247.                     request.open('GET', this.adfeed, true);
  248.                     request.onreadystatechange = function() {
  249.                         if (request.readyState == 4) {
  250.                             if (request.status == 200) {
  251.                                 var domParser = Components.classes["@mozilla.org/xmlextras/domparser;1"]
  252.                                                                                     .createInstance(Components.interfaces.nsIDOMParser);
  253.                                 var doc = domParser.parseFromString(request.responseText, "text/xml");
  254.                                 var entrys = doc.getElementsByTagName("entry");
  255.                                 var curEntry = 0;
  256.                                 if (entrys.length > 1) {
  257.                                     curEntry=Math.floor(Math.random()*entrys.length);
  258.                                 }
  259.                                 var links = entrys[curEntry].getElementsByTagName("link");
  260.                                 for (var i=0; i < links.length; i++) {
  261.                                     if (links[i].hasAttribute("type") && (links[i].getAttribute("type") == "text/html")) {
  262.                                         btshoppingbutton.shoppingimage.setAttribute("url", links[i].getAttribute("href"));
  263.                                     }
  264.                                     if (links[i].hasAttribute("type") && (links[i].getAttribute("type") == "image/jpeg")) {
  265.                                         btshoppingbutton.shoppingimage.setAttribute("src", links[i].getAttribute("href"));
  266.                                     }
  267.                                 }
  268.                             }
  269.                         }
  270.                     }
  271.                     request.send(null);
  272.                     ]]>
  273.                 </body>
  274.             </method>      
  275.             <method name="getString">
  276.                 <parameter name="id"/>
  277.                 <body>
  278.                     <![CDATA[
  279.                     var string;
  280.                     if (this.btBoomBundle) {
  281.                         try {
  282.                             string = this.btBoomBundle.getString(id);
  283.                         } catch(ex) {
  284.                         }
  285.                     }
  286.                     if (!string) {
  287.                         try {
  288.                             string = this.btClientBundle.getString(id);
  289.                         } catch(ex) {
  290.                         }
  291.                     }
  292.                     return string;
  293.                     ]]>
  294.                 </body>
  295.             </method>
  296.         </implementation>
  297.     </binding>
  298. </bindings>
  299.